package net.youball.service.impl;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import net.youball.dao.IConfigDao;
import net.youball.dao.ILoginInfoDao;
import net.youball.dao.IUserDao;
import net.youball.entity.BallLoginInfo;
import net.youball.entity.BallUser;
import net.youball.service.IUserService;
import net.youball.utils.page.Args;
import net.youball.utils.page.PageBean;



public class UserServiceImpl extends BaseServiceImpl<BallUser> implements IUserService{
	private IUserDao userDao;
	private IConfigDao configDao;
	private ILoginInfoDao loginInfoDao;
	public IUserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(IUserDao userDao) {
		this.userDao = userDao;
	}

	public boolean doValid(String name, String value) {
		// TODO Auto-generated method stub
		int i=userDao.valid(name, value);
		if(i<=0)
			return true;
		else
			return false;
	}
	
	public Integer doReg(BallUser user,BallLoginInfo loginInfo) {
		// TODO Auto-generated method stub
		user.setConfigId(1);
		Serializable uid=userDao.add(user);
		if(uid!=null){
			loginInfo.setUserId((Integer)uid);
			loginInfoDao.add(loginInfo);
			return (Integer)uid;
		}	
		return null;
	}
	public BallUser doLogin(String name,String pass){
		
		return userDao.login(name, pass);
	}
	
	public boolean doLoginInfo(BallLoginInfo loginInfo){
		Serializable id=loginInfoDao.add(loginInfo);
		if(id!=null)
		return true;
		return false;
	}

	public IConfigDao getConfigDao() {
		return configDao;
	}

	public void setConfigDao(IConfigDao configDao) {
		this.configDao = configDao;
	}

	public ILoginInfoDao getLoginInfoDao() {
		return loginInfoDao;
	}

	public void setLoginInfoDao(ILoginInfoDao loginInfoDao) {
		this.loginInfoDao = loginInfoDao;
	}

	public BallUser findById(Integer id) {
		// TODO Auto-generated method stub
		BallUser user= userDao.selectById(id);
		return user;
	}

	public void Test(){
		PageBean page=new PageBean();
		page.setBegin(0);
		page.setCount(2);
		Map<String,Args> map=new HashMap<String, Args>();
		/*Args args=new Args();
		args.setType("=");
		args.setValue("ss");
		map.put("nickName", args);
		
		Args args1=new Args();
		args1.setType("=");
		args1.setValue("sss");
		map.put("userEmail", args1);*/
		Args args1=new Args();
		args1.setComp("like");
		args1.setValue("y");
		map.put("userName", args1);
		Args args2=new Args();
		args2.setComp("likeright");
		args2.setValue("qq.com");
		//map.put("userEmail", args2);
		page.setArgs(map);
		
		userDao.paging(page);
	}

	public BallUser doEmailLogin(String email, String pass) {
		// TODO Auto-generated method stub
		
		return userDao.emailLogin(email, pass);
	}
	
	
}
